package com.three.service.impl;

import com.baor.baseUtil.R;
import com.three.dao.ClassesDao;
import com.three.dao.DailyLogsDao;
import com.three.domain.Attendance;
import com.three.domain.Businesstrips;
import com.three.domain.Dailylogs;
import com.three.domain.Leaves;
import com.three.service.DailyLogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class DailyLogsServletImpl implements DailyLogsService {

    @Autowired
    private DailyLogsDao dailyLogsDao;
//总端
    //日志列表
    @Override
    public R dailyLogsList(String keyword, Integer pageIndex, Integer pageSize,String date) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCountDailyLogs = dailyLogsDao.PageCountDailyLogs(keyword, date);
        pageCountDailyLogs = Math.ceil(pageCountDailyLogs / pageSize);
        List<Dailylogs> businesstripsList = dailyLogsDao.dailyLogsList(keyword, pageIndex, pageSize,date);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCountDailyLogs", pageCountDailyLogs);
        map.put("businesstripsList", businesstripsList);
        return R.ok(map);
    }

    //出差列表
    @Override
    public R businesstripsList(String keyword,Integer pageIndex, Integer pageSize,String date) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCountBusinesstrips = dailyLogsDao.PageCountBusinesstrips(keyword,date);
        pageCountBusinesstrips = Math.ceil(pageCountBusinesstrips / pageSize);
        List<Businesstrips> businesstripsList = dailyLogsDao.businesstripsList(keyword, pageIndex, pageSize,date);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCountBusinesstrips", pageCountBusinesstrips);
        map.put("businesstripsList", businesstripsList);
        return R.ok(map);
    }

    //请假列表
    @Override
    public R leavesList(String keyword,Integer pageIndex, Integer pageSize,String date) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCountLeaves = dailyLogsDao.PageCountLeaves(keyword,date);
        System.out.println(pageCountLeaves);
        pageCountLeaves = Math.ceil(pageCountLeaves / pageSize);
        List<Leaves> businesstripsList = dailyLogsDao.leavesList(keyword, pageIndex, pageSize,date);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCountLeaves", pageCountLeaves);
        map.put("businesstripsList", businesstripsList);
        return R.ok(map);
    }

    //出勤列表
    @Override
    public R attendanceList(String keyword, Integer pageIndex, Integer pageSize,String date) {
        pageIndex = (pageIndex - 1) * pageSize;
        double PageCountAttendance = dailyLogsDao.PageCountAttendance(keyword,date);
        System.out.println(PageCountAttendance);
        PageCountAttendance = Math.ceil(PageCountAttendance / pageSize);
        List<Attendance> attendancesList = dailyLogsDao.attendanceList(keyword, pageIndex, pageSize,date);
        Map<String, Object> map = new HashMap<>();
        map.put("PageCountAttendance", PageCountAttendance);
        map.put("attendancesList", attendancesList);
        return R.ok(map);
    }

    //教师端
    @Override
    public R dailyLogsListByTeacher(Map<String, Object> map) {
        int teacher_id = (int) map.get("teacher_id");
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        String date = (String) map.get("log_date");
        pageIndex = (pageIndex - 1) * pageSize;
        double PageCountDailyLogsByTeacher = dailyLogsDao.PageCountDailyLogsByTeacher(teacher_id,date);
        System.out.println(PageCountDailyLogsByTeacher);
        PageCountDailyLogsByTeacher = Math.ceil(PageCountDailyLogsByTeacher / pageSize);
        List<Dailylogs> classesList = dailyLogsDao.dailyLogsListByTeacher(teacher_id, pageIndex, pageSize,date);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("PageCountDailyLogsByTeacher", PageCountDailyLogsByTeacher);
        map2.put("classesList", classesList);
        return R.ok(map2);
    }
        //出差列表
        @Override
        public R businesstripsListByTeacher(Map<String, Object> map) {
            int teacher_id = (int) map.get("teacher_id");
            int pageIndex = (int) map.get("pageIndex");
            int pageSize = (int) map.get("pageSize");
            String date = (String) map.get("date");
            pageIndex = (pageIndex - 1) * pageSize;
            double PageCountBusinesstripsByTeacher = dailyLogsDao.PageCountBusinesstripsByTeacher(teacher_id,date);
            System.out.println(PageCountBusinesstripsByTeacher);
            PageCountBusinesstripsByTeacher = Math.ceil(PageCountBusinesstripsByTeacher / pageSize);
            List<Businesstrips> businesstripsList = dailyLogsDao.businesstripsListByTeacher(teacher_id, pageIndex, pageSize,date);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("PageCountBusinesstripsByTeacher", PageCountBusinesstripsByTeacher);
            map2.put("businesstripsList", businesstripsList);
            return R.ok(map2);
        }
        //请假列表
        @Override
        public R leavesListByTeacher(Map<String, Object> map) {
            int user_id = (int) map.get("user_id");
            int pageIndex = (int) map.get("pageIndex");
            int pageSize = (int) map.get("pageSize");
            String date = (String) map.get("date");
            pageIndex = (pageIndex - 1) * pageSize;
            double PageCountLeavesByTeacher = dailyLogsDao.PageCountLeavesByTeacher(user_id,date);
            System.out.println(PageCountLeavesByTeacher);
            PageCountLeavesByTeacher = Math.ceil(PageCountLeavesByTeacher / pageSize);
            List<Leaves> leavesList = dailyLogsDao.leavesListByTeacher(user_id, pageIndex, pageSize,date);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("PageCountLeavesByTeacher", PageCountLeavesByTeacher);
            map2.put("leavesList", leavesList);
            return R.ok(map2);
        }
        //出勤列表
        @Override
        public R attendanceListByTeacher(Map<String, Object> map) {
            int user_id = (int) map.get("user_id");
            int pageIndex = (int) map.get("pageIndex");
            int pageSize = (int) map.get("pageSize");
            String date = (String) map.get("date");
            pageIndex = (pageIndex - 1) * pageSize;
            double PageCountAttendanceByTeacher = dailyLogsDao.PageCountAttendanceByTeacher(user_id,date);
            System.out.println(PageCountAttendanceByTeacher);
            PageCountAttendanceByTeacher = Math.ceil(PageCountAttendanceByTeacher / pageSize);
            List<Attendance> attendancesList = dailyLogsDao.attendanceListByTeacher(user_id, pageIndex, pageSize,date);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("PageCountAttendanceByTeacher", PageCountAttendanceByTeacher);
            map2.put("attendancesList", attendancesList);
            return R.ok(map2);
        }

        //添加日常
        @Override
        public R addDailyLogs(Dailylogs dailylogs) {
            return R.ok(dailyLogsDao.addDailyLogs(dailylogs));
        }

        @Override
        public R addBusinesstrips(Businesstrips businesstrips) {
            return R.ok(dailyLogsDao.addBusinesstrips(businesstrips));
        }

        @Override
        public R addLeaves(Leaves leaves) {
            return R.ok(dailyLogsDao.addLeaves(leaves));
        }

    @Override
    public R addAttendance(Attendance attendance) {
        return R.ok(dailyLogsDao.addAttendance(attendance));
    }

}
